package com.chixing.day08_interface;

/**
 *把 A implements Comparable<T> 比较两个对象的先后顺序
 * 实现了自然排序
 *
 * TreeMap， TreeSet
 *
 *
 */
public class Product implements Comparable<Product>{
    private  String proName;
    private  int proSale;
    private  float proPrice;
    public Product(){}



    public Product(String proName,int proSale,float proPrice){
        this.proName=proName;
        this.proSale=proSale;
        this.proPrice=proPrice;
    }

    //两个商品比较先后顺序（先比较销量，再比较价格，再比较商品名称）
    @Override
    public int compareTo(Product anotherProduct) {
        if(this.proSale != anotherProduct.proSale)
            return this.proSale- anotherProduct.proSale;
        else if(this.proPrice != anotherProduct.proPrice)
            return (int) (this.proPrice - anotherProduct .proPrice);
        else
            return this.proName.compareTo(anotherProduct.proName);
    }
}
